<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>微信菜单</title>
<%@ include file="../common/importLib.jsp" %>
<script type="text/javascript" src="js/xxl.weixinmenu.js"></script>	
<script type="text/javascript">	
	$(function(){
		getAccountAndAppid();
	})
	var targetProtocol = "http:";
	if (window.location.protocol != targetProtocol){
		window.location.href = targetProtocol + window.location.href.substring(window.location.protocol.length);
	}
	var schoolName = "";
	$.ajax({
		   type: "POST",
		   url: getTimeURL("../maintain/userInfo/sessionUserInfo.do"),
		   async: false,
		   success: function(data){
			   schoolId = data.schoolId;
			   schoolName = data.schoolName + "(" + data.schoolCode + ")";
			   
			   
			   app_domain = data.myDomain;
		   }
		});
	/**
	 * 增删改查参数设置
	 */
	tableTitle = "菜单组";
	tableURL = getTimeURL("../weixin/weixinMenu/weixinMenuGroupList.do");
	toolbarView = 3;
	tableColumns = [[{field:'ck',width:30,
						formatter:function(value,rowData,rowIndex){
							if(rowData.schoolId == schoolId || rowData.schoolId == 0 ){
								return "<input type='checkbox' style='width:20px'/>";
							}
						} 
					},
					{field:'opt',title:'操作',width:150,align:'center', rowspan:1,
						formatter:function(value,rowData,rowIndex){							
							if(rowData.schoolId == schoolId || rowData.schoolId == 0 ){
								var queryUrl = 'weixinMenu/queryById.do?id=' + rowData.id;
								return "<a title='发布' class='xxl_linkbutton' iconCls='icon-release' href='javascript:buildmenu(\"" + rowData.id + "\")'>发布</a>"
								+"<a title='修改' class='xxl_linkbutton' iconCls='icon-edit' href='javascript:datagridUpdate(\"" + queryUrl + "\")'>修改</a>";
							}
						}
					}
	                ,{field:'id',title:'id',width:0,rowspan:1}
	                ,{field:'name',title:'组名',width:70,align:'center',rowspan:1}
					,{field:'createtime',title:'创建时间',width:250,rowspan:1,formatter:function(value,rowData,rowIndex){return new Date(value).toLocaleString();}}
// 					,{field:'schoolId',title:'学校ID',width:100,rowspan:1}
					]];
	
	var addWidth = 730; //添加窗口宽度
	var addHeight = 520; //添加窗口高度
	var addTitle = "添加菜单组"; //添加标题
	var updateWidth = 730; //修改窗口宽度
	var updateHeight = 520; //修改窗口高度
	var updateTitle = "修改菜单组"; //修改标题
	var updateDisableFlagUri = "weixinMenu/updateDisableFlag.do"; //禁用、起用记录
	var deleteUri = "weixinMenu/deleteByIds.do"; //删除记录
	
	/**
	 * 初始化添加表单
	 */	
	function initAddForm(){	
		if(app_account==''){
			$('#datagrid_add').window('close');
			$.messager.alert("操作失败","请先行设置微信公众号信息",'error');
			return ;
		}
		combobox_4("mtype",eval('[{id:"view",text:"链接"},{id:"click",text:"点击"}]'),false,"");
		treeDivId = '#tt' ;
		windowtype = 'add';
		$("#gid").val("");
		buildtree();
		addFormProcess("name","菜单",true);	
		baseFormValidator("name","菜单组名称",1,300);
	}
	
	/**
	 * 初始化修改表单
	 */
	function initUpdateForm(jsonObject){
		combobox_4("mtypeUpdate",eval('[{id:"view",text:"链接"},{id:"click",text:"点击"}]'),false,"");
		treeDivId = '#ttUpdate' ;
		windowtype = 'update';
		$("#gidUpdate").val(jsonObject.id);
		buildtree(jsonObject.id);
		$("#nameUpdate").val(jsonObject.name);
		$("#createtimeUpdate").html(new Date(jsonObject.createtime).toLocaleString());
		$("#idUpdate").val(jsonObject.id);
		updateFormProcess("nameUpdate","菜单");
		baseFormValidator("nameUpdate","菜单组名称",1,30);
	}
	
	/**
	 *删除记录之后执行函数
	 */
	function afterDelete(){
// 		0.0
	}
	
	function clearForm(){		
		$("#pId").val("");
	}
	
	
</script>
</head>
<body id="layout" class="easyui-layout">
	<div style="background: none repeat scroll 0% 0% #EFEFEF; height:68px; padding: 6px 2px; border-bottom: 1px solid #CCC;" region="north"  split="false" title="条件查询">
	<form  id="searchForm" >
	<table>
		<tr>			
			<td>菜单组组名：</td>
			<td>
			<input type="text" id="nameSearch" name="name" style="width: 300px"/>
			</td>			
			<td width="20px;"></td>
			<td><a class="easyui-linkbutton" id="search" iconCLs="icon-search"  onclick="searchTable()">搜索</a></td>
			<td><a class="easyui-linkbutton" iconCls="icon-undo" onclick="document.getElementById('searchForm').reset();clearForm();reload();">清空</a></td>
		</tr>
	</table>
	</form>
	</div>	
	<div region="center" style="font-family:微软雅黑">
		<!-- datagrid信息表 -->
		<table id="datagrid_table"></table>
	</div>
	<!-- 添加记录 -->
	<div id="datagrid_add">
		<form id="add_form" action="weixinMenu/addMenuGroup.do" method="post">
			<table border="0" width="670" class="xxl_tb_1" style="font-size:13px">
				<tbody>
						<tr>
							<td class="xxl_td_2">分组名：</td>
							<td><input type="text" id="name" name="name" class="xxl_ipt_2"/></td>
							<td><div id="nameTip" style="width:250px"></div></td>
						</tr>
						<tr>
							<td class="xxl_td_2">菜单内容：</td>
							<td class="xxl_td_2" colspan="1" >
								<a class="easyui-linkbutton" iconCls="icon-remove" onclick="removemenu('add')">移除该菜单</a>
							</td>		
						</tr>
						<tr>
							<td class="xxl_td_2" colspan="2" >
								<div class="easyui-panel" style="padding:5px;margin-top: 15px;">
									<div id="tt" class="easyui-tree"></div>
								</div>
							</td>
						</tr>
						<tr>
							<td class="xxl_td_2" colspan="2" >
								<a class="easyui-linkbutton" iconCls="icon-add" onclick="newparentmenu('add');">新增父菜单</a>
								<a class="easyui-linkbutton" iconCls="icon-add" onclick="newchildrenmenu('add');">新增子菜单</a>
								<a class="easyui-linkbutton" iconCls="icon-save" onclick="savemenu('add');">菜单项保存</a>
							</td>		
						</tr>
						
							<input id="menuId" type="hidden">
							<input id="gid" type="hidden">
							<input id="parentId" type="hidden" value="0">
							<tr>
								<td class="xxl_td_2">操作类型：</td>
								<td>
								<input type="text" id="mtype" name="mtype" class="xxl_ipt_2"/>
								
								</td>
								<td><div id="mtypeTip" style="width:250px"></div></td>
							</tr>
							<tr>
								<td class="xxl_td_2">名字：</td>
								<td><input type="text" id="muneName" class="xxl_ipt_2"/></td>
								<td><div id="muneNameTip" style="width:250px"></div></td>
							</tr>
							<tr>
								<td class="xxl_td_2">点击的关键词：</td>
								<td><input type="text" id="inputCode" class="xxl_ipt_2"/></td>
								<td><div id="inputCodeTip" style="width:250px"></div></td>
							</tr>
							<tr>
								<td class="xxl_td_2">跳转的链接：</td>
								<td>
								<textarea id="url" style="width: 250px; height: 120px; color: rgb(153, 153, 153);" ></textarea>
								<br/>
								<a class="easyui-linkbutton" iconCls="icon-redo" onclick="toOAuth('url')">转换为授权链接</a>
								<br/>
								<p style="color: red;"></p>
								</td>
								<td><div id="urlTip" style="width:250px"></div></td>
							</tr>				
					<tr>
						<td colspan="3" style="text-align: center">					
							<a class="easyui-linkbutton" iconCls="icon-ok" onclick="$('#add_form').submit();">添加</a>
							<a class="easyui-linkbutton" iconCls="icon-undo" onclick="document.getElementById('add_form').reset()">重置</a>
							<a class="easyui-linkbutton" iconCls="icon-cancel" onclick="$('#datagrid_add').window('close');">取消</a>
						</td>
					</tr>
				</tbody>
			</table>
		</form>
	</div>
	
	<!-- 修改记录 -->
	<div id="datagrid_update">
		<form id="update_form" action="weixinMenu/updateGroupByUId.do" method="post">
			<input type="hidden" id="idUpdate" name="id"/>
			<table border="0" width="670" class="xxl_tb_1">
				<tbody>
					<tr>
						<td class="xxl_td_2">分组名：</td>
						<td><input type="text" id="nameUpdate" name="name" class="xxl_ipt_2"/></td>
						<td><div id="nameUpdateTip" style="width:250px"></div></td>
					</tr>
					<tr>
						<td class="xxl_td_2">创建时间：</td>
						<td>
<!-- 						<input type="text" id="createtimeUpdate" name="createtime" class="xxl_ipt_2"/> -->
							<label id="createtimeUpdate"></label>
						</td>
						<td><div id="createtimeUpdateTip" style="width:250px"></div></td>
					</tr>
					<tr>
						<td class="xxl_td_2">菜单内容：</td>
						<td class="xxl_td_2" colspan="1" >
							<a class="easyui-linkbutton" iconCls="icon-remove" onclick="removemenu('update')">移除该菜单</a>
						</td>		
					</tr>
					<tr>
						<td class="xxl_td_2" colspan="2" >
							<div class="easyui-panel" style="padding:5px;margin-top: 15px;">
								<div id="ttUpdate" class="easyui-tree"></div>
							</div>
						</td>
					</tr>
					<tr>
						<td class="xxl_td_2" colspan="2" >
							<a class="easyui-linkbutton" iconCls="icon-add" onclick="newparentmenu('update');">新增父菜单</a>
							<a class="easyui-linkbutton" iconCls="icon-add" onclick="newchildrenmenu('update');">新增子菜单</a>
							<a class="easyui-linkbutton" iconCls="icon-save" onclick="savemenu('update');">菜单项保存</a>
						</td>		
					</tr>
					
						<input id="menuIdUpdate" type="hidden">
						<input id="gidUpdate" type="hidden">
						<input id="parentIdUpdate" type="hidden" value="0">
						<tr>
							<td class="xxl_td_2">操作类型：</td>
							<td>
							<input type="text" id="mtypeUpdate" name="mtype" class="xxl_ipt_2"/>
							
							</td>
							<td><div id="mtypeUpdateTip" style="width:250px"></div></td>
						</tr>
						<tr>
							<td class="xxl_td_2">名字：</td>
							<td><input type="text" id="muneNameUpdate" class="xxl_ipt_2"/></td>
							<td><div id="muneNameUpdateTip" style="width:250px"></div></td>
						</tr>
						<tr>
							<td class="xxl_td_2">点击的关键词：</td>
							<td><input type="text" id="inputCodeUpdate" class="xxl_ipt_2"/></td>
							<td><div id="inputCodeUpdateTip" style="width:250px"></div></td>
						</tr>
						<tr>
							<td class="xxl_td_2">跳转的链接：</td>
							<td>
							<textarea id="urlUpdate" style="width: 250px; height: 120px; color: rgb(153, 153, 153);" ></textarea>
							<br/>
							<a class="easyui-linkbutton" iconCls="icon-redo" onclick="toOAuth('urlUpdate')">转换为授权链接</a>
							</td>
							<td><div id="urlUpdateTip" style="width:250px"></div></td>
						</tr>
					
					
					<tr>
						<td colspan="3" style="text-align: center">
							<a class="easyui-linkbutton" iconCls="icon-ok" onclick="$('#update_form').submit();">修改</a>		
							<a class="easyui-linkbutton" iconCls="icon-cancel" onclick="$('#datagrid_update').window('close');">取消</a>
						</td>
					</tr>
				</tbody>
			</table>
		</form>
	</div>
</body>
</html>